﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.UI.MobileControls;
using System.Collections.Generic;
using System.Data.SqlClient;

namespace BankService
{
    public class TheNganHang
    {
        private string _maThe;
        private string _tenTaiKhoan;
        private DateTime _ngayHetHan;
        private double _soDuTK;

        #region "Get & set"        
        public string MaThe
        {
            get { return _maThe; }
            set { _maThe = value; }
        }
        
        public DateTime NgayHetHan
        {
            get { return _ngayHetHan; }
            set { _ngayHetHan = value; }
        }

        public string TenTaiKhoan
        {
            get { return _tenTaiKhoan; }
            set { _tenTaiKhoan = value; }
        }

        public double SoDuTK
        {
            get { return _soDuTK; }
            set { _soDuTK = value; }
        }

        #endregion

        public static List<TheNganHang> GetAll() 
        {
            List<TheNganHang> _list = new List<TheNganHang>();

            const string sql = "select * from TAIKHOAN tk join BLOCK bl on tk.MaTK = bl.MaTK";
            string cnStr = "Server =.\\SQLEXPRESS; Database=Bank_GK; Integrated Security=SSPI";

            SqlConnection cn = new SqlConnection(cnStr);
            SqlDataAdapter da = new SqlDataAdapter(sql, cn);

            DataTable dt = new DataTable();

            da.Fill(dt);

            foreach (DataRow row in dt.Rows)
            {
                DateTime _thoiGianKhoa = new DateTime(1,1,1);
                if (row["ThoiGianDong"].ToString() != "")
                {
                    _thoiGianKhoa = DateTime.Parse(row["ThoiGianDong"].ToString());
                }                
                if (_thoiGianKhoa < DateTime.Now)
                {
                    TheNganHang _the = new TheNganHang();
                    _the.MaThe = row["MaTK"].ToString();
                    _the.NgayHetHan = DateTime.Parse(row["NgayHetHan"].ToString());
                    _the.TenTaiKhoan = row["TenTK"].ToString();
                    _the.SoDuTK = double.Parse(row["SoDu"].ToString());
                    _list.Add(_the);
                }
            }

            return _list;
        }
        

    }
}
